package com.sendinfo.xwork.converter;

import com.sendinfo.xspring.util.GenericUtil;
import com.sendinfo.xspring.util.TxtUtil;
import com.sendinfo.xspring.util.enums.AbstractEnumSupport;

@SuppressWarnings("unchecked")
public class EnumConverter extends CustomizeConverter {
    @Override
    protected Object fromString(String value, Class clazz) {
	if (TxtUtil.isEmpty(value))
	    return null;
	if (AbstractEnumSupport.class.isAssignableFrom(clazz))
	    return GenericUtil.valueOf(clazz.asSubclass(AbstractEnumSupport.class), Integer.parseInt(value));
	else
	    return Enum.valueOf(clazz, value);
    }
}
